package com.csxy.dyq.controller;

import com.csxy.dyq.R;
import com.csxy.dyq.service.OssService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "oss", description = "文件上传服务")
@RestController
@RequestMapping("/edu_oss/fileoss")
public class OssController {
    @Autowired
    private OssService ossService;
    // 这里可以添加更多的文件上传相关接口方法，例如上传文件、删除文件等
    @Operation(summary = "上传图片到OSS")
    @PostMapping("/upload")
    public R uploadFile(@RequestParam(name = "file")MultipartFile file){
        // 接收前端传来的文件对象
        String url = ossService.uploadFileAvatar(file);
        // 返回上传后的文件访问路径
        return R.ok().data("url", url).message("文件上传成功");
    }

}
